package com.iflytek.iot.okhttp.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author yu 2020/6/16.
 */
@Component
@ConfigurationProperties(prefix = "spring.okhttp")
public class OkHttpConfigProperties {

    /**
     * 连接超时时间(ms)
     */
    private int connectTimeout = 1000;

    /**
     * 读超时时间(ms)
     */
    private int readTimeout = 1000;

    /**
     * 写超时时间(ms)
     */
    private int writeTimeout = 1000;

    /**
     * 连接池数量
     */
    private int maxIdleConnection = 10;

    /**
     * 连接保持时间(min)
     */
    private long keepAliveDuration = 5;

    /**
     * 代理配置
     */
    private OkHttpConfigProperties.NetProxy proxy;

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public int getReadTimeout() {
        return readTimeout;
    }

    public void setReadTimeout(int readTimeout) {
        this.readTimeout = readTimeout;
    }

    public int getWriteTimeout() {
        return writeTimeout;
    }

    public void setWriteTimeout(int writeTimeout) {
        this.writeTimeout = writeTimeout;
    }

    public int getMaxIdleConnection() {
        return maxIdleConnection;
    }

    public void setMaxIdleConnection(int maxIdleConnection) {
        this.maxIdleConnection = maxIdleConnection;
    }

    public long getKeepAliveDuration() {
        return keepAliveDuration;
    }

    public void setKeepAliveDuration(long keepAliveDuration) {
        this.keepAliveDuration = keepAliveDuration;
    }

    public NetProxy getProxy() {
        return proxy;
    }

    public void setProxy(NetProxy proxy) {
        this.proxy = proxy;
    }

    public static class NetProxy {

        /**
         * 是否启用代理
         */
        private Boolean enable = Boolean.TRUE;

        /**
         * 代理服务器地址
         */
        private String host = "127.0.0.1";

        /**
         * 代理服务器端口
         */
        private int port = 80;

        /**
         * 代理服务认证用户名
         */
        private String username;

        /**
         * 代理服务器认证密码
         */
        private String password;


        public Boolean getEnable() {
            return enable;
        }

        public void setEnable(Boolean enable) {
            this.enable = enable;
        }

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
